package cn.edu.cqut;

interface ComputerWeight
{
    public double computerWeight ();
}
class Television implements ComputerWeight
{

    @Override
    public double computerWeight() {
        return 30;
    }
}
class Computer implements ComputerWeight
{

    @Override
    public double computerWeight() {
        return 10;
    }
}
class WashMachine implements ComputerWeight
{

    @Override
    public double computerWeight() {
        return 200;
    }
}
class Truck {
    ComputerWeight[] x;
   double TotalWeight = 0;

    Truck(ComputerWeight[] x) {
        this.x = x;
    }

    public void setGoods(ComputerWeight[] x) {
        this.x = x;
    }

    public double getTotalWeights() {
        TotalWeight = 0;
for(int i=0;i<x.length;i++)
{
     TotalWeight+=x[i].computerWeight();
}
        return TotalWeight;
    }
}
public class CheckCarWeight {
    public static void main(String args[]) {
        ComputerWeight[] goods = new ComputerWeight[650]; 
        for (int i = 0; i < goods.length; i++) {
            if (i % 3 == 0)
                goods[i] = new Television();
            else if (i % 3 == 1)
                goods[i] = new Computer();
            else if (i % 3 == 2)
                goods[i] = new WashMachine();
        }
        Truck truck = new Truck(goods);
        System.out.printf("\n 货⻋装载的货物重量:%-8.5f kg\n", truck.getTotalWeights());
        goods = new ComputerWeight[68];
        for (int i = 0; i < goods.length; i++) {
            if (i % 2 == 0)
                goods[i] = new Television();
            else
                goods[i] = new WashMachine();
        }
        truck.setGoods(goods);
        System.out.printf("货⻋装载的货物重量:%-8.5f kg\n", truck.getTotalWeights());
    }
}
